package spindles.gwt.client;

import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class TasksPanel extends Composite implements ClickListener{
	
	public static final String SPINDLES_DETECTION_TASK = "Spindles Detection";
	public static final String DATA_IMPORT_TASK = "Data Import";
	public static final String USERS_TASK = "Users Management";
	public static final String SETTINGS_TASK = "Settings";	
	
	private VerticalPanel panel = new VerticalPanel();
	
	private final HTML tasksTitle = new HTML("Tasks");
	
	public TasksPanel(){		
		SimplePanel outer = new SimplePanel();
	    outer.setWidget(panel);	    

	    initWidget(outer);
	    setStyleName("spindles-Tasks");	    
	    
	    tasksTitle.setTitle("Tasks");	    
	    tasksTitle.setStyleName("spindles-TasksTitle");	    
	    
	    panel.add(tasksTitle);
	    panel.add(createTask(SPINDLES_DETECTION_TASK, "spindles"));
		panel.add(createTask(DATA_IMPORT_TASK, "import"));		
		panel.add(createTask(SETTINGS_TASK, "settings"));
		panel.add(createTask(USERS_TASK, "users"));
		
	}
	
	public RightPanel getSpindleDetectionPanel(){
		return new SpindleDetectionPanel();
	}
	
	public RightPanel getImportPanel(){
		return new ImportPanel();
	}

	public void onClick(Widget sender) {
		if(sender.getTitle().equals(SPINDLES_DETECTION_TASK)){
			Spindles.get().setRightPanel(getSpindleDetectionPanel());			
		} else if(sender.getTitle().equals(DATA_IMPORT_TASK)){
			Spindles.get().setRightPanel(getImportPanel());
		} else if(sender.getTitle().equals(SETTINGS_TASK)){
			Spindles.get().setRightPanel(new SettingsPanel());
		} else {
			Window.alert(sender.getTitle() + " task is not yet implemented...");	
		}
	}
	
	private Hyperlink createTask(String text, String history){
		Hyperlink hl = new Hyperlink(text, history);
	    hl.setTitle(text);	    
	    hl.addClickListener(this);
	    
		return hl;
	}
	
	public int getTitleHeight(){
		return tasksTitle.getOffsetHeight();
	}

}
